<?php

include_once( dirname(__FILE__).'/../cform.php' );
include_once( dirname(__FILE__).'/../basic/cfield.php' );

$form_fields = 	array(
		Array(
			'title' 	=> 'Текстовое поле',
			'name'		=> 'ftext',
			'type'		=> 'text',
			'value'		=> '',
			'errors' 	=> _nonempty_ | _number_
		),
		Array(
			'title' 	=> 'Email',
			'name'		=> 'femail',
			'type'		=> 'text',
			'value'	 	=> 'dddd',
			'errors' 	=> _nonempty_ | _email_
		)
);

function check_errors( & $form_fields, $silence = 0 ){
	global $err_info;

	# _NON_EMPTY_
	$mass[_nonempty_][0]['value'] = '';
	$mass[_nonempty_][0]['result'] = false;

	$mass[_nonempty_][1]['value'] = 'aaa';
	$mass[_nonempty_][1]['result'] = true;

	# _EMAIL_
	$mass[_email_][0]['value'] = 'qweqwe';
	$mass[_email_][0]['result'] = false;

	$mass[_email_][1]['value'] = 'aaa@aaa.aaa';
	$mass[_email_][1]['result'] = true;

	$mass[_email_][2]['value'] = 'aaa.aaa@aaa.aa.aaa';
	$mass[_email_][2]['result'] = true;

	# _DATE_
	$mass[_date_][0]['value'] = '200612.12';
	$mass[_date_][0]['result'] = false;

	$mass[_date_][1]['value'] = '12.12.2005';
	$mass[_date_][1]['result'] = true;

	$mass[_date_][2]['value'] = '13.13.2004';
	$mass[_date_][2]['result'] = false;

	# _TIME_
	$mass[_time_][0]['value'] = '200612.12';
	$mass[_time_][0]['result'] = false;

	$mass[_time_][1]['value'] = '30:23';
	$mass[_time_][1]['result'] = false;

	$mass[_time_][2]['value'] = '17:13';
	$mass[_time_][2]['result'] = true;

	# _DATETIME_
	$mass[_datetime_][0]['value'] = '2006.12.12';
	$mass[_datetime_][0]['result'] = false;

	$mass[_datetime_][1]['value'] = '30:23';
	$mass[_datetime_][1]['result'] = false;

	$mass[_datetime_][2]['value'] = '12.12.2006 12:10';
	$mass[_datetime_][2]['result'] = true;

	# _NUMBER_
	$mass[_number_][0]['value'] = '12.87';
	$mass[_number_][0]['result'] = true;

	$mass[_number_][1]['value'] = '13.98.87';
	$mass[_number_][1]['result'] = false;

	$mass[_number_][2]['value'] = 'sdsd';
	$mass[_number_][2]['result'] = false;

	$mass[_number_][3]['value'] = '132';
	$mass[_number_][3]['result'] = true;

	$mass[_number_][4]['value'] = '1e5';
	$mass[_number_][4]['result'] = false;

	# _ALPHASTRING_
	$mass[_alphastring_][0]['value'] = 'asassas_ ksdjd';
	$mass[_alphastring_][0]['result'] = true;

	$mass[_alphastring_][1]['value'] = 'нашаsdsd q';
	$mass[_alphastring_][1]['result'] = false;

	$mass[_alphastring_][2]['value'] = 's123d';
	$mass[_alphastring_][2]['result'] = false;

	# _LOGIN_
	$mass[_login_][0]['value'] = 'asassas_ ksdjd';
	$mass[_login_][0]['result'] = false;

	$mass[_login_][1]['value'] = 'нашаsdsd';
	$mass[_login_][1]['result'] = false;

	$mass[_login_][2]['value'] = 'qwerty';
	$mass[_login_][2]['result'] = true;

	$mass[_login_][3]['value'] = 's12sdsds3d';
	$mass[_login_][3]['result'] = false;

	# _DIRNAME_
	$mass[_dirname_][0]['value'] = 'asassas_ ksdjd';
	$mass[_dirname_][0]['result'] = false;

	$mass[_dirname_][1]['value'] = 'нашаsdsd';
	$mass[_dirname_][1]['result'] = false;

	$mass[_dirname_][2]['value'] = 'qwerty';
	$mass[_dirname_][2]['result'] = true;

	$mass[_dirname_][3]['value'] = 's12sdsds3d';
	$mass[_dirname_][3]['result'] = false;

	$field = & new CField( $form_fields[0], $err_info, 1 );
	$keys = array_keys($mass);

	$k_index = sizeof($keys);
	for($k=0; $k<$k_index; $k++){
		if ( !$silence )
		    print "<b>Проверка на: ".$err_info[$keys[$k]]['MESS']."</b><br>";
		$index = sizeof( $mass[$keys[$k]] );
		for($i=0; $i<$index; $i++){
			$field->ch_error = $keys[$k];
			$field->set_value( $mass[$keys[$k]][$i]['value'] );
			if ( !$silence ){
				print "Должно быть ".( $mass[$keys[$k]][$i]['result'] ? 'TRUE' : 'FALSE' )." получено ".( !$field->ch_find_error ? 'TRUE' : 'FALSE' );
				if ( $mass[$keys[$k]][$i]['result'] == (bool)!$field->ch_find_error )
				    print "<font color='GREEN'> ... OK!</font><br>";
				else
				    print "<font color='RED'> ... FAIL!</font><br>";
			}
		}
		if ( !$silence ) print "<br>";
	}
	$field->Free();
}

check_errors( $form_fields );

?>